<!doctype html>
<html lang="zh-CN">
<head>
    <title>日志</title>
    {% include 'admin/common/header.html' %}
    <link rel="stylesheet" href="/static/admin/admin/css/other/console2.css"/>
</head>
<body class="pear-container">

<div class="layui-card">
    <div class="layui-card-body">
        <div class="layui-tab layui-tab-card">
            <ul class="layui-tab-title">
                <li class="layui-this">登录日志</li>
                <li>访问日志</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <table style="margin-top: 10px;" id="log-login-table" lay-filter="log-login-table"></table>
                </div>
                <div class="layui-tab-item">
                    <table style="margin-top: 10px;" id="log-access-table"
                           lay-filter="log-access-table"></table>
                </div>
            </div>
        </div>
    </div>
</div>


{% include 'admin/common/footer.html' %}
<script type="text/html" id="log-createTime">
    {{ '  {{layui.util.toDateString(d.create_at,  "yyyy-MM-dd HH:mm:ss")}' |safe }}}
</script>
<script type="text/html" id="log-status">
    {{ '{{#if (d.success == true) { }}
    <span style="color: green">成功</span>
    {{# }else if(d.success == false){ }}
    <span style="color: red">失败</span>
    {{# } }}'|safe }}
</script>
<script>
  layui.use(['table', 'form', 'jquery', 'element', 'util'], function() {
    let table = layui.table;
    let form = layui.form;

    let MODULE_PATH = '/logs/';

    const get_columns = () => [
      [
        {title: 'ID', field: 'id', align: 'center'},
        {title: '请求方式', field: 'method', align: 'center'},
        {title: '接口', field: 'url', align: 'center'},
        {title: '浏览器', field: 'user_agent', align: 'center'},
        {title: '操作地址', field: 'ip', align: 'center'},
        {title: '访问时间', field: 'create_at', templet: '#log-createTime', align: 'center'},
        {title: '操作人ID', field: 'uid', align: 'center'},
        {title: '描述', field: 'desc', align: 'center'},
        {title: '访问状态', templet: '#log-status', align: 'center'},
      ],
    ];

    table.render({
      parseData: parserTableData,
      elem: '#log-access-table',
      url: MODULE_PATH + 'access_log',
      page: true,
      cols: get_columns(),
      skin: 'line',
      toolbar: false,
    });

    table.render({
      parseData: parserTableData,
      elem: '#log-login-table',
      url: MODULE_PATH + 'login_log',
      page: true,
      cols: get_columns(),
      skin: 'line',
      toolbar: false,
    });
  });
</script>
</body>
</html>
